<template>
	<page-wrapper :page-path="'/pages/discover/discover'" :navLeft="'none'" 
	 :navBackgroundColor="primaryColor" :navTitleStyle="navTitleStyle">
		<view class="discover-container">

			<!-- 搜索栏 -->
			<view class="search-bar">
				<view class="search-input">
					<uni-icons type="search" size="18" color="#999"></uni-icons>
					<input type="text" placeholder="搜索理财知识、记账技巧" />
				</view>
			</view>

			<!-- 内容区域 -->
			<scroll-view scroll-y class="content-area">
				<!-- 轮播图 -->
				<swiper class="banner" indicator-dots autoplay circular :interval="3000" :duration="500">
					<swiper-item v-for="(item, index) in banners" :key="index">
						<image :src="item.image" mode="aspectFill"></image>
					</swiper-item>
				</swiper>

				<!-- 功能导航 -->
				<view class="feature-nav">
					<view class="feature-item" v-for="(item, index) in features" :key="index" @click="navigateToFeature(item.path)">
						<view class="feature-icon" :style="{ backgroundColor: item.bgColor }">
							<uni-icons :type="item.icon" size="24" color="#333"></uni-icons>
						</view>
						<text class="feature-name">{{ item.name }}</text>
					</view>
				</view>

				<!-- 理财知识 -->
				<view class="section">
					<view class="section-header">
						<text class="section-title">理财知识</text>
						<view class="section-more" @click="navigateToMore('finance')">
							<text>查看更多</text>
							<uni-icons type="right" size="14" color="#999"></uni-icons>
						</view>
					</view>

					<view class="article-list">
						<view class="article-item" v-for="(item, index) in financeArticles" :key="index" @click="viewArticle(item)">
							<image class="article-image" :src="item.image" mode="aspectFill"></image>
							<view class="article-info">
								<text class="article-title">{{ item.title }}</text>
								<view class="article-meta">
									<text class="article-source">{{ item.source }}</text>
									<text class="article-time">{{ item.time }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>

				<!-- 记账技巧 -->
				<view class="section">
					<view class="section-header">
						<text class="section-title">记账技巧</text>
						<view class="section-more" @click="navigateToMore('tips')">
							<text>查看更多</text>
							<uni-icons type="right" size="14" color="#999"></uni-icons>
						</view>
					</view>

					<view class="tips-list">
						<view class="tips-item" v-for="(item, index) in accountingTips" :key="index" @click="viewArticle(item)">
							<text class="tips-title">{{ item.title }}</text>
							<view class="tips-meta">
								<text class="tips-tag">{{ item.tag }}</text>
								<text class="tips-views">{{ item.views }}次浏览</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 社区热门 -->
				<view class="section">
					<view class="section-header">
						<text class="section-title">社区热门</text>
						<view class="section-more" @click="navigateToMore('community')">
							<text>查看更多</text>
							<uni-icons type="right" size="14" color="#999"></uni-icons>
						</view>
					</view>

					<view class="community-list">
						<view class="community-item" v-for="(item, index) in communityPosts" :key="index" @click="viewPost(item)">
							<view class="user-info">
								<image class="user-avatar" :src="item.avatar" mode="aspectFill"></image>
								<text class="user-name">{{ item.username }}</text>
							</view>
							<text class="post-content">{{ item.content }}</text>
							<view class="post-images" v-if="item.images && item.images.length">
								<image 
									v-for="(img, imgIndex) in item.images" 
									:key="imgIndex" 
									:src="img" 
									mode="aspectFill"
								></image>
							</view>
							<view class="post-actions">
								<view class="action-item">
									<uni-icons type="chat" size="18" color="#999"></uni-icons>
									<text>{{ item.comments }}</text>
								</view>
								<view class="action-item">
									<uni-icons type="heart" size="18" color="#999"></uni-icons>
									<text>{{ item.likes }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</page-wrapper>
</template>

<script>
import { themeMixin } from '@/utils/theme.js';
import PageWrapper from '@/components/page-wrapper/page-wrapper.vue';

export default {
	components: {
		PageWrapper
	},
	mixins: [themeMixin],
	data() {
		return {
			navTitleStyle: {
				color: '#FFFFFF'
			},
			banners: [
				{ image: '/static/images/banner1.jpg' },
				{ image: '/static/images/banner2.jpg' },
				{ image: '/static/images/banner3.jpg' }
			],
			features: [
				{ name: '理财课堂', icon: 'info', bgColor: '#FFE7B2', path: '/pages/discover/finance-class' },
				{ name: '记账达人', icon: 'medal', bgColor: '#FFCDD2', path: '/pages/discover/accounting-master' },
				{ name: '省钱攻略', icon: 'gift', bgColor: '#C8E6C9', path: '/pages/discover/save-money' },
				{ name: '社区讨论', icon: 'chat', bgColor: '#BBDEFB', path: '/pages/discover/community' }
			],
			financeArticles: [
				{
					id: 1,
					title: '新手如何开始投资理财？从0到1的理财入门指南',
					image: '/static/images/finance1.jpg',
					source: '财经日报',
					time: '2小时前'
				},
				{
					id: 2,
					title: '30岁前要完成的5个理财目标，你达成了几个？',
					image: '/static/images/finance2.jpg',
					source: '理财周刊',
					time: '昨天'
				}
			],
			accountingTips: [
				{
					id: 1,
					title: '高效记账的7个小技巧，让你轻松管理财务',
					tag: '实用技巧',
					views: 1253
				},
				{
					id: 2,
					title: '如何养成每日记账的好习惯？这些方法很有效',
					tag: '习惯养成',
					views: 986
				},
				{
					id: 3,
					title: '记账软件选择指南：哪款最适合你的需求？',
					tag: '工具推荐',
					views: 1578
				}
			],
			communityPosts: [
				{
					id: 1,
					username: '理财达人',
					avatar: '/static/images/avatar1.jpg',
					content: '分享一下我的存钱经验：每月工资一到账，先拿出30%存起来，剩下的再规划使用，坚持三年，存款已经超过20万了！',
					images: ['/static/images/post1.jpg'],
					comments: 28,
					likes: 156
				},
				{
					id: 2,
					username: '省钱小能手',
					avatar: '/static/images/avatar2.jpg',
					content: '推荐一个超级实用的购物省钱技巧：在购物网站加入购物车但不要立即购买，等1-2天后经常会收到降价提醒或优惠券！',
					images: [],
					comments: 45,
					likes: 234
				}
			]
		}
	},
	methods: {
		// 导航到功能页面
		navigateToFeature(path) {
			uni.navigateTo({
				url: path
			});
		},
		
		// 查看更多
		navigateToMore(type) {
			uni.navigateTo({
				url: `/pages/discover/more?type=${type}`
			});
		},
		
		// 查看文章
		viewArticle(article) {
			uni.navigateTo({
				url: `/pages/discover/article?id=${article.id}`
			});
		},
		
		// 查看帖子
		viewPost(post) {
			uni.navigateTo({
				url: `/pages/discover/post?id=${post.id}`
			});
		}
	}
}
</script>

<style lang="scss">
.discover-container {
	background-color: $background-color;
	position: relative;
	display: flex;
	flex-direction: column;

	
	// 搜索栏
	.search-bar {
		padding: 20rpx 30rpx;
		background-color: #fff;
		flex-shrink: 0;
		
		.search-input {
			height: 70rpx;
			background-color: #f5f5f5;
			border-radius: 35rpx;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			
			uni-icons {
				margin-right: 10rpx;
			}
			
			input {
				flex: 1;
				height: 100%;
				font-size: 28rpx;
			}
		}
	}
	
	// 内容区域
	.content-area {
		flex: 1;
		height: 70vh; /* 设置一个固定高度 */
		
		// 轮播图
		.banner {
			height: 300rpx;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		// 功能导航
		.feature-nav {
			display: flex;
			justify-content: space-around;
			padding: 30rpx 20rpx;
			background-color: #fff;
			margin-bottom: 20rpx;
			
			.feature-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				
				.feature-icon {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-bottom: 15rpx;
				}
				
				.feature-name {
					font-size: 24rpx;
					color: $text-color;
				}
			}
		}
		
		// 内容区块
		.section {
			background-color: #fff;
			padding: 30rpx;
			margin-bottom: 20rpx;
			
			.section-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				
				.section-title {
					font-size: 32rpx;
					font-weight: bold;
					color: $text-color;
				}
				
				.section-more {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: $text-color-lighter;
				}
			}
			
			// 文章列表
			.article-list {
				.article-item {
					display: flex;
					padding: 20rpx 0;
					border-bottom: 1rpx solid #f5f5f5;
					
					&:last-child {
						border-bottom: none;
					}
					
					.article-image {
						width: 180rpx;
						height: 120rpx;
						border-radius: 10rpx;
						margin-right: 20rpx;
					}
					
					.article-info {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						
						.article-title {
							font-size: 28rpx;
							color: $text-color;
							line-height: 1.4;
							display: -webkit-box;
							-webkit-line-clamp: 2;
							-webkit-box-orient: vertical;
							overflow: hidden;
						}
						
						.article-meta {
							display: flex;
							justify-content: space-between;
							font-size: 24rpx;
							color: $text-color-lighter;
						}
					}
				}
			}
			
			// 记账技巧列表
			.tips-list {
				.tips-item {
					padding: 20rpx 0;
					border-bottom: 1rpx solid #f5f5f5;
					
					&:last-child {
						border-bottom: none;
					}
					
					.tips-title {
						font-size: 28rpx;
						color: $text-color;
						margin-bottom: 10rpx;
					}
					
					.tips-meta {
						display: flex;
						justify-content: space-between;
						font-size: 24rpx;
						
						.tips-tag {
							color: $primary-color;
							background-color: rgba(255, 216, 77, 0.2);
							padding: 4rpx 10rpx;
							border-radius: 4rpx;
						}
						
						.tips-views {
							color: $text-color-lighter;
						}
					}
				}
			}
			
			// 社区帖子列表
			.community-list {
				.community-item {
					padding: 20rpx 0;
					border-bottom: 1rpx solid #f5f5f5;
					
					&:last-child {
						border-bottom: none;
					}
					
					.user-info {
						display: flex;
						align-items: center;
						margin-bottom: 15rpx;
						
						.user-avatar {
							width: 60rpx;
							height: 60rpx;
							border-radius: 50%;
							margin-right: 15rpx;
						}
						
						.user-name {
							font-size: 28rpx;
							color: $text-color;
							font-weight: bold;
						}
					}
					
					.post-content {
						font-size: 28rpx;
						color: $text-color;
						line-height: 1.5;
						margin-bottom: 15rpx;
					}
					
					.post-images {
						display: flex;
						margin-bottom: 15rpx;
						
						image {
							width: 200rpx;
							height: 200rpx;
							border-radius: 10rpx;
							margin-right: 10rpx;
							
							&:last-child {
								margin-right: 0;
							}
						}
					}
					
					.post-actions {
						display: flex;
						
						.action-item {
							display: flex;
							align-items: center;
							margin-right: 40rpx;
							
							uni-icons {
								margin-right: 6rpx;
							}
							
							text {
								font-size: 24rpx;
								color: $text-color-lighter;
							}
						}
					}
				}
			}
		}
	}
}
</style> 